package org.hong.monkey.crawl

import org.zeromq.ZMQ.Poller
import org.zeromq.ZMQ.Socket

/**
 * Created by open on 2016/12/15.
 */
class WebkitDriver(val clientID:String,
                   val protocol:String,
                   val wkpid:Int,
                   var socket:Socket,
                   val poller:Poller) {

  var pageid:Long = 0
  var isFailed = false
  var isClosed = false

  val machine = protocol.replaceAll("tcp://", "")

  def reconnect() = {
    if (!isClosed) {
      poller.unregister(socket)
      val t = socket.getType()
      socket.close()
      socket = WebkitUtils.context.socket(t)
      socket.connect(protocol)
      poller.register(socket)
    }
  }

  def close() = {
    if (!isClosed) {
      poller.unregister(socket)
      socket.close()
      isClosed = true
    }
  }

}
